package com.ruoyi.eservice.service.impl;

import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.base.BaseService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.eservice.mapper.CommentsMapper;
import com.ruoyi.eservice.pojo.entity.Comments;
import com.ruoyi.eservice.service.ICommentsService;

/**
 * 评价列表Service业务层处理
 *
 * @author Jackson
 * @date 2022-11-14
 */
@Service
public class CommentsServiceImpl extends BaseService implements ICommentsService
{
    @Autowired
    private CommentsMapper commentsMapper;

    /**
     * 查询评价列表
     *
     * @param commentsId 评价列表主键
     * @return 评价列表
     */
    @Override
    public Comments selectCommentsByCommentsId(Long commentsId)
    {
        return commentsMapper.selectById(commentsId);
    }

    /**
     * 查询评价列表列表
     *
     * @param comments 评价列表
     * @return 评价列表
     */
    @Override
    public List<Comments> selectCommentsList(Comments comments)
    {
        QueryWrapper<Comments> queryWrapper = createSelWrapper(Comments.class);
        queryWrapper.lambda()
                .eq(StringUtils.isNotNull(comments.getCommentsId()), Comments::getCommentsId, comments.getCommentsId())
                .eq(StringUtils.isNotEmpty(comments.getCommedContent()), Comments::getCommedContent, comments.getCommedContent())
        ;
        return commentsMapper.selectList(queryWrapper);
    }

    /**
     * 新增评价列表
     *
     * @param comments 评价列表
     * @return 结果
     */
    @Override
    public int insertComments(Comments comments)
    {
        comments.setCreateBy(SecurityUtils.getUsername());
        comments.setCreateTime(DateUtils.getNowDate());
        comments.setUpdateBy(SecurityUtils.getUsername());
        comments.setUpdateTime(DateUtils.getNowDate());
        int rows = commentsMapper.insert(comments);
        return rows;
    }

    /**
     * 修改评价列表
     *
     * @param comments 评价列表
     * @return 结果
     */
    @Override
    public int updateComments(Comments comments)
    {
        comments.setUpdateBy(SecurityUtils.getUsername());
        comments.setUpdateTime(DateUtils.getNowDate());

        return commentsMapper.updateById(comments);
    }

    /**
     * 批量删除评价列表
     *
     * @param commentsIds 需要删除的评价列表主键
     * @return 结果
     */
    @Override
    public int deleteCommentsByCommentsIds(Long[] commentsIds)
    {
        return commentsMapper.deleteBatchIds(Arrays.asList(commentsIds));
    }

    /**
     * 删除评价列表信息
     *
     * @param commentsId 评价列表主键
     * @return 结果
     */
    @Override
    public int deleteCommentsByCommentsId(Long commentsId)
    {
        return commentsMapper.deleteById(commentsId);
    }
}
